﻿
/*----------------------------------------------------------------
 * 创建时间：2023/7/31 16:02:49
 * 作  者：wenlli 
 * 项  目：Minotaur.App.Core.Redis 
 * 描  述：缓存操作
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时  间：
 * 修改说明：
 * 
 *----------------------------------------------------------------*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Minotaur.App.Core.Redis
{
    /// <summary>
    /// 缓存操作
    /// </summary>
    public interface IRedisClient : ICommonInterface
    {
        /// <summary>
        /// 添加缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expiry"></param>
        void Add<T>(string key, T value, DateTime expiry);
        /// <summary>
        /// 添加缓存-TimeSpan
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expiry"></param>
        void Add<T>(string key, T value, TimeSpan slidingExpiration);
        /// <summary>
        /// 根据key获取数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 根据key移除缓存
        /// </summary>
        /// <param name="key"></param>
        void Remove(string key);

        /// <summary>
        /// 判断key是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool Exists(string key);

        #region HASH类型封装
        /// <summary>
        /// 判断该字段是否存在 hash 中
        /// </summary>
        /// <param name="hashID">hash数据集</param>
        /// <param name="hashField">字段ID</param>
        /// <returns></returns>
        bool HashExists(string hashID, string hashField);

        /// <summary>
        /// 删除hashid数据集中的key数据
        /// </summary>
        /// <param name="hashID"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        bool HashRemove(string hashID, string hashField);


        /// <summary>
        /// 向HASH数据集中添加数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hashID"></param>
        /// <param name="hashField"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        bool HashAdd<T>(string hashID, string hashField, T Value);
        /// <summary>
        /// 向HASH数据集中添加数据
        /// 如果存在则不添加，不存在则添加
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hashID"></param>
        /// <param name="hashField"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        bool HashAddNotExist<T>(string hashID, string hashField, T Value);

        /// <summary>
        /// 获取hash集合中的某个元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hashID"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        T HashGet<T>(string hashID, string hashField);

        /// <summary>
        /// 获取hash集合中的某些元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hashID"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        List<T> HashGet<T>(string hashID, string[] hashField);

        /// <summary>
        /// 获取所有hashid数据集的key/value数据集合 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IDictionary<string, string> HashGetAll(string hashId);
        #endregion
    }
}
